package cl.BEANs;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import cl.POJOs.*;
import cl.DAOs.*;
import java.util.List;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class AdminBean {

    public String user;
    public String pass;
    
    

    public String verificardatos() throws Exception {
        AdminDAO adao = new AdminDAO();
        String resultado = "error";
        int numero = adao.verificarDatos(user, pass);
        if (numero != 0) {
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("admin", user);
            resultado = "intranetadmin";
        }
        return resultado;
    }
    public boolean verificarSesion() {
        boolean estado;

        if (FacesContext.getCurrentInstance().getExternalContext()
                .getSessionMap().get("admin") == null) {
            estado = false;
        } else {
            estado = true;
        }

        return estado;
    }

    public String cerrarSesion() {
        FacesContext.getCurrentInstance().getExternalContext()
                .invalidateSession();
        return "index";
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

}
